package ttc.sftp.data;

import java.util.ArrayList;
import java.util.List;
import ttc.sftp.R;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;

public class InstalledApp {
	public static List<PackageInfo> apps;
	public static PackageManager pm;

	class AppInfo {
		String appname = "";
		String pname = "";
		String versionName = "";
		int versionCode = 0;
		Drawable icon;
	}

	private ArrayList<AppInfo> getInstalledPackages() {
		ArrayList<AppInfo> res = new ArrayList<AppInfo>();
		for (int i = 0; i < apps.size(); i++) {
			PackageInfo p = apps.get(i);

			AppInfo newInfo = new AppInfo();
			newInfo.appname = p.applicationInfo.loadLabel(pm).toString();
			newInfo.pname = p.packageName;
			newInfo.versionName = p.versionName;
			newInfo.versionCode = p.versionCode;
			newInfo.icon = p.applicationInfo.loadIcon(pm);
			res.add(newInfo);
		}
		return res;
	}
	public static int getIdIcon(String ext)
	{
		if(ext.compareToIgnoreCase("apk")==0)
			return R.drawable.file_apk;
		if(ext.compareToIgnoreCase("txt")==0||ext.compareToIgnoreCase("csv")==0||ext.compareToIgnoreCase("xml")==0)
			return R.drawable.file_text;
		if(ext.compareToIgnoreCase("htm")==0||ext.compareToIgnoreCase("html")==0||ext.compareToIgnoreCase("php")==0)
			return R.drawable.file_html;
		if(ext.compareToIgnoreCase("png")==0||ext.compareToIgnoreCase("gif")==0||ext.compareToIgnoreCase("jpg")==0||ext.compareToIgnoreCase("jpeg")==0||ext.compareToIgnoreCase("bmp")==0)
			return R.drawable.file_picture;
		if(ext.compareToIgnoreCase("mp3")==0||ext.compareToIgnoreCase("wav")==0||ext.compareToIgnoreCase("ogg")==0||ext.compareToIgnoreCase("mid")==0||ext.compareToIgnoreCase("midi")==0||ext.compareToIgnoreCase("amr")==0)
			return R.drawable.file_audio;
		if(ext.compareToIgnoreCase("mpeg")==0||ext.compareToIgnoreCase("3gp")==0)
			return R.drawable.file_video;
		if(ext.compareToIgnoreCase("jar")==0||ext.compareToIgnoreCase("zip")==0||ext.compareToIgnoreCase("rar")==0||ext.compareToIgnoreCase("gz")==0)
			return R.drawable.file_zip;
		return R.drawable.file_default;
	}
	public static String getStringType(String ext)
	{
		if(ext.compareToIgnoreCase("apk")==0)
			return "application/vnd.android.package-archive";
		if(ext.compareToIgnoreCase("txt")==0)
			return "text/plain";
		if(ext.compareToIgnoreCase("csv")==0)
			return "text/csv";
		if(ext.compareToIgnoreCase("xml")==0)
			return "text/xml";
		if(ext.compareToIgnoreCase("htm")==0)
			return "text/html";
		if(ext.compareToIgnoreCase("html")==0)
			return "text/html";
		if(ext.compareToIgnoreCase("php")==0)
			return "text/php";
		if(ext.compareToIgnoreCase("png")==0)
			return "image/png";
		if(ext.compareToIgnoreCase("gif")==0)
			return "image/gif";
		if(ext.compareToIgnoreCase("jpg")==0)
			return "image/jpg";
		if(ext.compareToIgnoreCase("jpeg")==0)
			return "image/jpeg";
		if(ext.compareToIgnoreCase("bmp")==0)
			return "image/bmp";
		if(ext.compareToIgnoreCase("mp3")==0)
			return "audio/mp3";
		if(ext.compareToIgnoreCase("wav")==0)
			return "audio/wav";
		if(ext.compareToIgnoreCase("ogg")==0)
			return "audio/x-ogg";
		if(ext.compareToIgnoreCase("mid")==0)
			return "audio/mid";
		if(ext.compareToIgnoreCase("midi")==0)
			return "audio/midi";
		if(ext.compareToIgnoreCase("amr")==0)
			return "audio/AMR";
		if(ext.compareToIgnoreCase("mpeg")==0)
			return "video/mpeg";
		if(ext.compareToIgnoreCase("3gp")==0)
			return "video/3gpp";
		if(ext.compareToIgnoreCase("jar")==0)
			return "application/java-archive";
		if(ext.compareToIgnoreCase("zip")==0)
			return "application/zip";
		if(ext.compareToIgnoreCase("rar")==0)
			return "application/x-rar-compressed";
		if(ext.compareToIgnoreCase("gz")==0)
			return "application/gzip";
		return null;
	}
}
